package com.shadow.study.shiro.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shadow.study.shiro.entity.ShiroUserEntity;
import com.shadow.study.shiro.mapper.ShiroUserMapper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Slf4j
@Service
public class ShiroUserService extends ServiceImpl<ShiroUserMapper, ShiroUserEntity> implements IService<ShiroUserEntity> {

    @Resource
    private ShiroUserMapper shiroUserMapper;

    public ShiroUserEntity selectByName(final String name) {
        if (StringUtils.isNotEmpty(name)) {
            LambdaQueryWrapper<ShiroUserEntity> wrapper = new LambdaQueryWrapper<ShiroUserEntity>()
                    .eq(ShiroUserEntity::getName, name)
                    .last("limit 1");
            return shiroUserMapper.selectOne(wrapper);
        }
        return null;
    }


}
